var http = require('http')
var fs = require('fs')
var server = http.createServer()
server.on('request', function (req, res) {
  console.log('收到客户端请求，请求路径是：' + req.url)
  var parseObj = new URL(req.url, 'http://localhost:3000')
  var url = parseObj.pathname
  console.log(url)
  if (url === '/') {
    fs.readFile('./index.html', function (err, data) {
      if (err) {
        return res.end('404 Not Found')
      }
      res.end(data)
    })
  }
  else if (url.indexOf('/ui') === 0) {
    res.end('welcome ui')
  }
  else {
    res.end('NOT')
  }
})
server.listen(3000, function () {
  console.log('服务器启动成功了，可以通过http://127.0.0.1:3000/ 进行访问')
})